package com.zj.healthmanage.controller;

import com.github.pagehelper.PageInfo;
import com.zj.healthmanage.entity.PageResult;
import com.zj.healthmanage.entity.QueryPageBean;
import com.zj.healthmanage.entity.Result;
import com.zj.healthmanage.service.OrderlistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orderlist")
@Api(value = "预约列表",description = "预约列表")
public class OrderListController {

    @Autowired
    private OrderlistService orderlistService;

    @ApiOperation(value = "分页查询预约列表",httpMethod = "POST")
    @RequestMapping("/queryOrderListByPage")
    public PageResult queryOrderListByPage(@RequestBody Map queryPage){
        PageInfo list = orderlistService.queryOrderListByPage(queryPage);
        return new PageResult(list.getTotal(),list.getList());
    }

    @ApiOperation(value = "新增预约",httpMethod = "POST")
    @RequestMapping("/addOrderList")
    public Result addOrderList(@RequestBody Map orderList, String[] setmealIdList){
        try {
            orderlistService.addOrderList(orderList, setmealIdList);
            return new Result(true, "预约成功");
        }catch (Exception ex){
            ex.printStackTrace();
            return new Result(false,"预约失败");
        }
    }

    @ApiOperation(value = "删除预约",httpMethod = "POST")
    @RequestMapping("/deleteOrderList")
    public Result deleteOrderList(Integer id){
        try{
            orderlistService.deleteByPrimaryKey(id);
            return new Result(true,"删除预约成功");
        }catch (Exception ex){
            ex.printStackTrace();
            return new Result(false,"删除预约失败");
        }
    }

    @ApiOperation(value = "查询预约的套餐",httpMethod = "POST")
    @RequestMapping("/querySetMealIdsById")
    public Result querySetMealIdsById(Integer id){
        List<Integer> setmealIdList = orderlistService.querySetMealIdsById(id);
        return new Result(true,"查询成功",setmealIdList);
    }

    @ApiOperation(value = "编辑预约",httpMethod = "POST")
    @RequestMapping("/editOrderList")
    public Result editOrderList(@RequestBody Map OrderList,String[] setmealIdList){

        try {
            orderlistService.editOrderList(OrderList, setmealIdList);
            return new Result(true,"更新预约成功");
        }catch (Exception ex){
            ex.printStackTrace();
            return new Result(false, "更新预约失败");

        }
    }

    @ApiOperation(value = "编辑到诊状态",httpMethod = "POST")
    @RequestMapping("/editOrderStatus")
    public Result editOrderStatus(Integer id ,String orderStatus){
        try {
            orderlistService.editOrderStatus(id, orderStatus);
            return new Result(true,"更新到诊状态成功");
        } catch (Exception ex){
            return new Result(false, "更新到诊状态失败");
        }
    }
}